package com.rr;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author zhuangcanrun
 * @Date 2021/11/22/23:46
 * @description
 **/

public class PoiDemo1 {
    public static void main(String[] args) throws IOException {
        XSSFWorkbook excel = new XSSFWorkbook(new FileInputStream(new File("poi-demo/src/main/resources/demo1.xlsx")));
        //读取Excel文件中第一个Sheet标签页
        XSSFSheet sheet = excel.getSheetAt(0);
        //遍历Sheet标签页，获得每一行数据
        for (Row row : sheet) {
            //遍历行，获得每个单元格对象
            for (Cell cell : row) {
                String cellType = cell.getCellType().name();
                String value = cellType.equals("STRING") ? cell.getStringCellValue() : cellType.equals("NUMERIC") ? String.valueOf(cell.getNumericCellValue()) : "";
                System.out.println(value);
            }
        }
        //关闭资源
        excel.close();
    }
}
